<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${'$'}{SYSTEM_NAME}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${'$'}{pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${'$'}{FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${'$'}{pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${'$'}{FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${'$'}{pageContext.request.contextPath}/static/js/zTree_v3/css/metroStyle/metroStyle.css?v=${'$'}{FILE_VERSION}" type="text/css">
</head>
<body>
	<div class="layui-fluid">
       	<div class="layui-card">
         	<div class="layui-card-header">${generatorTable.tableComment}</div>
         	<div class="layui-card-body">
				<div class="layui-row layui-col-space10">
					<div class="layui-col-xs2">
						<div style="border: 1px solid #ccc;max-height: 550px;min-height:400px; overflow: auto;">
							<ul id="treeRegion" class="ztree">
								加载中...
							</ul>
						</div>
					</div>
					<div class="layui-col-xs10 layui-form" style="padding-left: 15px">
						<input type="hidden" name="parentId"  id="parentId" >

					<#if generatorTable.hasQuery gt 0>
						<div class="layui-form-item">
							<#if generatorTable.fieldList?exists && generatorTable.fieldList?size gt 0>
								<#list generatorTable.fieldList as fieldItem >
								<#if fieldItem.isQuery =='1'>
									<#if (fieldItem.inputType =='1' || fieldItem.inputType =='2') >
							<div class="layui-inline">
								<label class="layui-form-label">${fieldItem.columnComment!""}：</label>
								<div class="layui-input-inline">
									<input type="text" id="${fieldItem.fieldName}" class="layui-input">
								</div>
							</div>

									</#if>
									<#if fieldItem.inputType =='3'>
							<div class="layui-inline">
								<label class="layui-form-label">${fieldItem.columnComment!""}：</label>
								<div class="layui-input-inline">
									<input type="text" id="${fieldItem.fieldName}" placeholder="点击选择${fieldItem.columnComment!""}"
										   class="layui-input" readonly="readonly" />
								</div>
							</div>

									</#if>
									<#if fieldItem.inputType =='6'>
							<div class="layui-inline">
								<label class="layui-form-label">${fieldItem.columnComment!""}：</label>
								<div class="layui-input-inline">
									<select id="${fieldItem.fieldName}">
										<option value="">请选择${fieldItem.columnComment!""}</option>
										<c:forEach items="${'$'}{${fieldItem.paramName}_MAP}" var="t">
											<option value="${'$'}{t.key }">${'$'}{t.value }</option>
										</c:forEach>
									</select>
								</div>
							</div>
									</#if>
								</#if>
								</#list>
							</#if>
							<div class="layui-inline">
								<button class="layui-btn" onclick="reload()">查询</button>
							</div>
						</div>
						<hr class="layui-bg-green">
						</#if>

						<table class="layui-table" lay-filter="tableId" id="layerTable">
						</table>
					</div>
				</div>
         	</div>
       	</div>
  	</div>

	<script type="text/html" id="toolbar">
		<div class="layui-btn-container">
			<button class="layui-btn" onclick="addLayer('/${generatorTable.moudleName}/${generatorTable.shiro}/add/input');">新增</button>
			<button class="layui-btn" onclick="modi('/${generatorTable.moudleName}/${generatorTable.shiro}/edit/input');">编辑</button>
			<button class="layui-btn layui-btn-danger" onclick="deleteBatch('/${generatorTable.moudleName}/${generatorTable.shiro}/del/deleteByIds');">删除</button>
		</div>
	</script>
  	
	<script type="text/html" id="barTpl">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

	<script src="${'$'}{pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${'$'}{FILE_VERSION}"></script>
  	<script src="${'$'}{pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${'$'}{FILE_VERSION}"></script>
  	<script src="${'$'}{pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${'$'}{FILE_VERSION}"></script>

	<script src="${'$'}{pageContext.request.contextPath}/static/js/zTree_v3/js/jquery.ztree.core.js?v=${'$'}{FILE_VERSION}"></script>
	<script src="${'$'}{pageContext.request.contextPath}/static/js/zTree_v3/js/jquery.ztree.excheck.js?v=${'$'}{FILE_VERSION}"></script>
	<script src="${'$'}{pageContext.request.contextPath}/static/js/zTree_v3/js/jquery.ztree.exedit.js?v=${'$'}{FILE_VERSION}"></script>
	<script src="${'$'}{pageContext.request.contextPath}/static/js/common/zTree.drop.js?v=${'$'}{FILE_VERSION}"></script>
	<script src="${'$'}{pageContext.request.contextPath}/static/js/common/coreTree-2.0.0.js?v=${'$'}{FILE_VERSION}"></script>
  	<script>
		var setting = {
			data: {
				simpleData: {
					enable: true
				}
			},
			edit: {
				enable: false
			},
			async: {
				enable: true,
				url: getUrl
			},
			callback : {
				onClick: treeOnClick
			}
		};

		function getUrl(treeId, treeNode) {
			return  getContextPath() + '/${generatorTable.moudleName}/${generatorTable.shiro}/list/getByParentId?parentId=' + treeNode.id;
		}

		function treeOnClick(event, treeId, treeNode) {
			parentName = treeNode.name;
			reload(treeNode.id);
		}

  		var table;
	  	layui.config({
	  		base: getContextPath() + '/static/layuiadmin/' //静态资源所在路径
	  	}).extend({
	  	}).use(['table', 'element', 'laydate'], function() {
			<#if generatorTable.inputTypes?contains("3")>
			var laydate = layui.laydate;
				<#if generatorTable.fieldList?exists && generatorTable.fieldList?size gt 0>
					<#list generatorTable.fieldList as fieldItem >
						<#if fieldItem.inputType =='3' && fieldItem.isQuery =='1'>
			laydate.render({
				elem: '#${fieldItem.fieldName}'
				,type: 'date'
				,range: false
			});

						</#if>
					</#list>
				</#if>
			</#if>
			table = layui.table;
			table.render({
				elem : '#layerTable',
				even : "true",
				toolbar: '#toolbar',
				defaultToolbar: ['filter', 'exports', 'print'],
				limit : 10,
				limits : [ 10, 20, 30 ],
				id : 'tableId',
				url : getContextPath() + '/${generatorTable.moudleName}/${generatorTable.shiro}/list/listInfo',
				page : true,
				method : 'post',
				cols : [[
					{checkbox : true,fixed : true}
					<#if generatorTable.fieldList?exists && generatorTable.fieldList?size gt 0>
					<#list generatorTable.fieldList as fieldItem >
						<#if fieldItem.listShow !='0'>
							<#if fieldItem.inputType =='3'>
					,{field : '${fieldItem.fieldName}',width : 180, title : '${fieldItem.columnComment!""}',templet : '<div>{{layui.util.toDateString(d.${fieldItem.fieldName}, "yyyy-MM-dd")}}</div>'}
							<#else>
					,{field : '${fieldItem.fieldName}<#if fieldItem.paramName?exists && fieldItem.paramName?length gt 0>Name</#if>',width : 120,title : '${fieldItem.columnComment!""}'}
							</#if>
						</#if>
					</#list>
					</#if>
					,{fixed: 'right', minWidth:240, align:'center',title:"操作", toolbar: '#barTpl'}
				]],
				request : {
					pageName : 'current',
					limitName : 'size'
				}
			});

			table.on('tool(tableId)', function(obj) {
				var data = obj.data;
				if (obj.event === 'del') {
					deleteById(data,obj,'/${generatorTable.moudleName}/${generatorTable.shiro}/del/deleteById');
				} else if (obj.event === 'edit') {
					addLayer('/${generatorTable.moudleName}/${generatorTable.shiro}/edit/input', data.id);
					updateTableCell = obj;
				}
			});
			treeReload("/${generatorTable.moudleName}/${generatorTable.shiro}/list/getByParentId");
		});

		function reload(pId) {
			if(typeof(pId) != "undefined")
				$('#parentId').val(pId);
			table.reload('tableId'<#if generatorTable.hasQuery gt 0>,{
				where :{
					"parentId": $('#parentId').val()
					<#if generatorTable.fieldList?exists && generatorTable.fieldList?size gt 0>
						<#list generatorTable.fieldList as fieldItem >
							<#if fieldItem.isQuery =='1' && (fieldItem.inputType =='1' || fieldItem.inputType =='2'
								|| fieldItem.inputType =='3' || fieldItem.inputType =='6' )>
					,"${fieldItem.fieldName}": ${'$'}("#${fieldItem.fieldName}").val()
							</#if>
						</#list>
					</#if>
				}
			}</#if>);
		}

  	</script>
</body>
</html>
